package src.dump;
import java.io.*;
import java.net.URL;
/**
 **  @author honghua.he 2013-12-28 01:08:51
 ** 
 */

public class ResourceURLServer {

public static String getURLResource(String urlStr) throws Exception {
    URL resourceUrl = new URL(urlStr);
    InputStream inputStr = (InputStream) resourceUrl.getContent();
    BufferedReader in = new BufferedReader(new InputStreamReader(inputStr));
    String line;
    String content = "";
    while ((line = in.readLine()) != null) {
        content += line + "\n";
    }
    return content;
}

public static void main(String[] args) {
    try {
        System.out.println("begin");
        String url = "http://table.finance.yahoo.com/table.csv?s=600000.ss";
        String content = getURLResource(url);
        if (content.length() == 0) {
            System.out.println("Failed to get " + url);
            return;
        } 
        FileWriter fw = new FileWriter("./test");
        PrintWriter pw = new PrintWriter(fw);
        BufferedWriter bw = new BufferedWriter(fw);
        bw.write("#" + url + "\n");
        bw.write(content);
        bw.flush();
        fw.close();
        bw.close();
        System.out.println("end");
    } catch (Exception e) {
        e.printStackTrace();
    }
}
}


